package com.xxgc.springboot.controller.exception;

import com.google.gson.Gson;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @program: springboot
 * @description: 系统父异常
 * @author: Mr.abel(ShiJiaYi)
 * @create: 2022-09-22 08:46
 **/
@Data
@Slf4j
public class BaseException extends RuntimeException {
    private static final long serialVersionUID = 1L;
    private Gson gson = new Gson();
    /**
     * 所属模块
     */
    private String module;

    /**
     * 错误码
     */
    private String code;

    /**
     * 错误码对应的传入参数
     */
    private Object args;

    /**
     * 错误消息
     */
    private String defaultMessage;

    /**
     * 接口路径 通过AOP注入
     */
    private String path;

    /**
     * 错误的方法名
     */
    private String methodName;


    public BaseException(String module, String code, Object args, String defaultMessage) {
        this.module = module;
        this.code = code;
        //对象转json
        log.info(gson.toJson(args));
        this.args = gson.toJson(args);
        this.defaultMessage = defaultMessage;
    }

    @Override
    public String toString() {
        return "BaseException{" +
                "module='" + module + '\'' +
                ", code='" + code + '\'' +
                ", args=" + args +
                ", defaultMessage='" + defaultMessage + '\'' +
                ", path='" + path + '\'' +
                ", methodName='" + methodName + '\'' +
                '}';
    }
}
